<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加指纹</title>
  <link rel="shortcut icon" href="__PUBLIC__/favicon.ico">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__PUBLIC__/style/template.css" media="all">
</head>
<body>
  <div style="margin:30px;">
    <div class="layui-form">  
        <div class="layui-card layui-card-add">            
          <div class="layui-form-item">
            <label class="layui-form-label"><span class="required">*</span>应用名称</label>
            <div class="layui-input-block">
              <input type="text" name="app_name" required placeholder="请输入应用名称" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">应用版本</label>
            <div class="layui-input-block">
              <input type="text" name="app_version"  placeholder="[选填项] 请输入应用的版本号" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">应用类型</label>
              <div class="layui-input-block">
                <select name="app_type" lay-verify="">
                  <option value=""></option>
                  <option value="CMS系统">CMS系统</option>
                  <option value="解析容器">解析容器</option>
              </select>
              </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">开发脚本</label>
            <div class="layui-input-block">
              <select name="app_script" lay-verify="">
                <option value=""></option>
                <option value="PHP">PHP</option>
                <option value="ASP.NET">ASP.NET</option>
                <option value="ASP">ASP</option>
                <option value="JSP">JSP</option>
                <option value="Python">Python</option>
                <option value="Go">Go</option>
                <option value="Perl">Perl</option>
                <option value="ColdFusion">ColdFusion</option>
            </select>
            </div>
          </div>
        </div>
        <div class="layui-card layui-card-add">
          <div class="layui-form-item">
            <label class="layui-form-label"><span class="required">*</span>识别方式</label>
            <div class="layui-input-block">
              <select name="finger_match_type" lay-verify="">
                <option value="1">关键字匹配</option>
                <option value="2">正则匹配</option>
                <option value="3">返回码匹配</option>
            </select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"><span class="required">*</span>请求路径</label>
            <div class="layui-input-block">
              <input type="text" name="finger_uri" placeholder="请输入具体路径，需以/开头，如/index.php" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"><span class="required">*</span>请求方式</label>
            <div class="layui-input-block">
              <select name="finger_method" lay-verify="">
                <option value="1">GET请求</option>
                <option value="2">POST请求</option>
            </select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">POST数据</label>
            <div class="layui-input-block">
              <input type="text" name="finger_post_data" placeholder="[选填项] 仅当请求方式为POST时，填写该项有效" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">POST类型</label>
            <div class="layui-input-block">
              <select name="finger_content_type" lay-verify="">
                <option value="">[选填项] 仅当请求方式为POST时该项有效</option>
                <option value="application/x-www-form-urlencoded">application/x-www-form-urlencoded</option>
                <option value="multipart/form-data">multipart/form-data</option>
                <option value="application/json">application/json</option>
                <option value="text/xml">text/xml</option>
                <option value="binary (application/octet-stream)">binary (application/octet-stream)</option>
            </select>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">Cookies</label>
            <div class="layui-input-block">
              <input type="text" name="finger_cookies" placeholder="[选填项] 带入请求的Cookies信息" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">指纹特征</label>
            <div class="layui-input-block">
              <input type="text" name="finger_signature" placeholder="[选填项] 请输入匹配的指纹特征" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">指纹描述</label>
            <div class="layui-input-block">
              <textarea name="finger_desc" placeholder="[选填项] 请输入指纹的简要描述" class="layui-textarea"></textarea>
            </div>
          </div>
        </div>
        <div class="layui-card layui-card-add">
          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-inline">
              <button class="layui-btn layui-btn-danger" lay-submit lay-filter="finger-test"><i class="layui-icon">&#xe857;</i> 测试</button>  
            </div>
            <div class="layui-inline">
              <button class="layui-btn" lay-submit lay-filter="finger-submit"><i class="layui-icon">&#xe609;</i> 提交</button>
            </div>
          </div>
        </div>
      </div>
  </div>

  
  <script src="__PUBLIC__/layui/layui.js"></script>  
  <script>
    layui.use('form', function(){
        var form = layui.form
        ,$ = layui.$;
        
        //提交
        form.on('submit(finger-submit)', function(obj){
          $.post("/Home/Ajax/ajax_add_finger" , JSON.stringify(obj.field) ,function(d){
            layer.msg(d.msg, {
                time: 1500,
                end: function() {
                  if(d.error == 0){
                    parent.layer.close(parent.layer.getFrameIndex(window.name)); // 关闭当前 iframe 的弹出层
                  }
                }
            });
          },"json");
        });

        //测试
        form.on('submit(finger-test)', function(obj){
          layer.open({
            type: 1,
            title: '指纹测试',
            content: `
                <div style="padding: 20px;">
                    <input type="text" id="customInput" placeholder="请输入测试URL，例如https://www.google.com" class="layui-input" style="width: 100%">
                </div>`,
            area: ['600px', '180px'],
            btn: ['测试', '取消'],
            yes: function(index, layero) {
                var inputVal = $('#customInput').val();
                if (inputVal) {
                  obj.field.target = inputVal;
                  $.post("/Home/Ajax/ajax_test" , JSON.stringify(obj.field) ,function(d){
                    layer.msg(d.msg);
                  },"json");
                } else {
                  layer.msg('请正确输入测试URL');
                }
                layer.close(index);
            },
            btn2: function(index, layero) {
                layer.close(index);
            }
          });
        });
    });
  </script>
</body>
</html>
